<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <title>扫雷</title>
</head>
<link rel="stylesheet" href="./css/page.css">
<link rel="stylesheet" href="./css/mine.css">

<script>
    //全局变量区
    let MINENUM = 0;    //表示地雷的数量
</script>
<script>
    function get() {
        const temp = document.getElementById('mine-num')
        try {
            const num = Number(temp.value)
            if (num > 1 && num <= 50) {
                init(num)
            }
            else {
                alert('数字必须大于1,小于等于50!')
            }
        } catch (error) {
            alert('输入框内仅能输入一个数字！')
        }
        temp.value = "";
        return 0;
    }
</script>

<body>
    <h1 class="title">welcome!</h1>
    <div class="body">
        <div class="nav">
            <span>选择地图规模：</span>
            <button onclick="init(9)">9 x 9</button>
            <button onclick="init(16)">16 x 16</button>
            <button onclick="init(30)">30 x 30</button>
            <br />
            <input id="mine-num" type="number" placeholder="自定义地图大小(n)" />
            <button onclick="get()">确定</button>
        </div>
        <div id="body">

        </div>
    </div>
    <script src="./js/init.js"></script>
    <script src="./js/state.js"></script>
    <script src="./js/mine.js"></script>
</body>
<script>
    // document.body.onmouseover = function (e) {   //反馈当前鼠标在哪个元素上
    //     e = e || e.event;
    //     let node = e.target || e.srcElement;
    //     if (window._lastNode != node) {
    //         console.log(node);
    //     }
    // }
    // document.body.onkeypress = function (e) {    //反馈当前按下了键盘的哪个键
    //     const keynum = window.event ? e.keyCode : e.which;
    //     const keychar = String.fromCharCode(keynum);
    //     console.log(keynum, keychar)
    // }
    document.oncontextmenu = function (e) { //取消右键弹窗
        return false;
    }
    document.getElementById('mine-num').onkeypress = function (e) {     //在输入数字的时候按键
        const keynum = window.event ? e.keyCode : e.which;
        if (keynum === 13) {    //如果按下了回车键
            get();
        }
    }
</script>

</html>